package cn.yingyu5658.lbl;

import java.io.PrintStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

/**
 * @author yingyu5658
 */
public class LuBuLu {
    Scanner sc;
    String one;
    String two;
    public int times;

    public LuBuLu() {
        this.sc = new Scanner(System.in);
        this.times = 0;
    }

    /**
     * 在第一次启动时展示开屏页面、帮助、定义switch分支调用命令方法
     */
    public void command() {
        while (true) {
            if (this.times == 0) {
                System.out.println(" __       __    __  .______    __    __   __       __    __                                                                                                                       \n|  |     |  |  |  | |   _  \\  |  |  |  | |  |     |  |  |  |                                                                                                                      \n|  |     |  |  |  | |  |_)  | |  |  |  | |  |     |  |  |  |                                                                                                                      \n|  |     |  |  |  | |   _  <  |  |  |  | |  |     |  |  |  |                                                                                                                      \n|  `----.|  `--'  | |  |_)  | |  `--'  | |  `----.|  `--'  |                                                                                                                      \n|_______| \\______/  |______/   \\______/  |_______| \\______/                                                                                                                       \n                                                                                                                                                                                  \n.___  ___.      ___       _______   _______          .______   ____    ____          ____    ____  __  .__   __.   ___________    ____  __    __   _____     __    _____    ___   \n|   \\/   |     /   \\     |       \\ |   ____|         |   _  \\  \\   \\  /   /          \\   \\  /   / |  | |  \\ |  |  /  _____\\   \\  /   / |  |  |  | | ____|   / /   | ____|  / _ \\  \n|  \\  /  |    /  ^  \\    |  .--.  ||  |__            |  |_)  |  \\   \\/   /            \\   \\/   /  |  | |   \\|  | |  |  __  \\   \\/   /  |  |  |  | | |__    / /_   | |__   | (_) | \n|  |\\/|  |   /  /_\\  \\   |  |  |  ||   __|           |   _  <    \\_    _/              \\_    _/   |  | |  . `  | |  | |_ |  \\_    _/   |  |  |  | |___ \\  | '_ \\  |___ \\   > _ <  \n|  |  |  |  /  _____  \\  |  '--'  ||  |____          |  |_)  |     |  |                  |  |     |  | |  |\\   | |  |__| |    |  |     |  `--'  |  ___) | | (_) |  ___) | | (_) | \n|__|  |__| /__/     \\__\\ |_______/ |_______|         |______/      |__|                  |__|     |__| |__| \\__|  \\______|    |__|      \\______/  |____/   \\___/  |____/   \\___/  \n                                                                                                                                                                                  ");
            }

            System.out.println("卢布卢 v1.4");
            LocalDate date = LocalDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            PrintStream var10000 = System.out;
            String var10001 = date.format(formatter);
            var10000.println("你在" + var10001 + "奇了星雨并打开本软件，来看看老天让不让你卢吧！");
            System.out.println("========================================");
            System.out.println("输入'/help'获取帮助");
            switch (this.sc.nextLine()) {
                case "/help":
                    this.help();
                    break;
                case "/lbl":
                    this.luMa();
                    break;
                case "/exit":
                    System.exit(0);
                    break;
                case "/coott":
                    if ("/coott".equals(sc.nextLine())) {
                        Scanner sc1 = new Scanner(System.in);
                        System.out.println("请输入您的第一个选项。");
                        String one = sc1.nextLine();
                        System.out.println("请输入您的第二个选项。");
                        String two = sc1.nextLine();
                        this.chooseOneOfTheTwo(one, two);
                    }
                    break;
                case "/cofm":
                    chooseOneFromMany();
                    break;
                default:
                    this.clear();
                    System.out.println("不存在该指令！将在1000ms后回到主页面。");
                    this.sleep();
                    return;
            }
            ++times;
            System.out.println("*调试信息* 运行轮数： " + this.times);
        }
    }

    /**
     * 程序休眠，目前仅用于输入命令错误时
     */
    public void sleep() {
        long start = System.currentTimeMillis();

        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long end = System.currentTimeMillis();
    }


    /**
     * /lbl命令调用此方法，随机布尔值，为true时卢，为false时不卢
     */
    public void luMa() {
        this.clear();
        boolean lbl = (new Random()).nextBoolean();
        if (lbl) {
            clear();
            System.out.println("------------------------------------");
            System.out.println("疯狂的鹿，不停的蛇，浓厚的鲸！！！！！");
            System.out.println("------------------------------------");
        } else {
            clear();

            System.out.println("------------------------------------");
            System.out.println("别让欲望击穿你的意志！");
            System.out.println("------------------------------------");
        }
    }

    /**
     * /coott命令调用此方法，随机布尔值，true为用户输入的第一个选项，反之为第二个选项
     * @param one 用户输入的第一个选项
     * @param two 用户输入的第二个选项
     */
    public void chooseOneOfTheTwo(String one, String two) {
        this.clear();
        this.one = one;
        this.two = two;
        boolean coott = (new Random()).nextBoolean();
        if (coott) {
            this.clear();
            System.out.println("老天帮你选了：" + this.one);
        } else {
            System.out.println("老天帮你选了：" + this.two);
        }
        System.out.println("========================================");
    }

    /**
     * /help命令调用此方法，显示所有命令的用途
     */
    public void help() {
        this.clear();
        System.out.println("===帮助页面===");
        System.out.println("'/lbl' 询问老天是否开卢");
        System.out.println("'/coott' 进入二选一模式");
        System.out.println("'/exit' 退出");
        System.out.println("'/cofm' 进入多选一模式");
    }

    /**
     * 清屏方法，一般会在其他功能方法中的第一行首先调用，打印大量空白字符来达到清屏的效果
     */
    public void clear() {
        for (int i = 0; i < 500; ++i) {
            System.out.println("");
        }
    }

    /**
     * /cofm命令调用此方法，把用户输入的字符串保存到ArrayList集合中，生成随机数，以生成的随机数为索引获取元素并输出。
     */
    public void chooseOneFromMany() {
        ArrayList choicesList = new ArrayList();
        Random r = new Random();
        clear();
        System.out.println("===多选一界面===");
        System.out.println("请输入选项总数");
        int choicesCount = sc.nextInt(); // 定义变量用于记录选项总数
        sc.nextLine();
        for (int i = 1; i < choicesCount; ++i) {
            System.out.println("请输入您的第" + i + "个选项");
            String chices = sc.nextLine();
            choicesList.add(chices);
        }
        int randomIndex = r.nextInt((choicesCount));
        System.out.println("老天帮你选了第" + (randomIndex + 1) + "个：" + choicesList.get(randomIndex));
    }

}
